import os

from manager.tool.Read_Properties import Properties

"""
    文件路径配置管理
"""
# 项目根目录
BASE_PATH = os.path.dirname(os.path.dirname(__file__))

# 读取测试用例数据(yml)父目录
BASE_DATA_PATH = BASE_PATH + "/data"


# 获取文件中指定的环境
#
def get_file_environment():
    environment = 'dev'
    try:
        r = Properties((BASE_PATH + '/config/environment.properties'), 'utf-8')  # 操作 properties 对象
        environment = r.get("ENVIRONMENT")
    except FileNotFoundError as e:
        print(f"指定文件未找到,{e}")
    except KeyError as e:
        print(f"key未找到,{e}")
    return environment


# 切换环境
ENVIRONMENT = get_file_environment()

# 环境变量根目录 path
BASE_ENVIRONMENT_PATH = BASE_PATH + "/config/env/"
# 签名密钥根据环境切换
SIGNS = {
    'dev': {
        'key': '2bCP63N7EP7a8bTNTjDbbsrwQSERapxF',
        'secret': 'b06c75b58d1701ff470119a4114f8b45'
    },
    'pro': {
        'key': 'xgj8zgvoxGMNn7410TVsKgJ5Ack0bOtN',
        'secret': 'eF2WIl7uf5k2zFFmkM1sAXGRWo7X54Ni'
    }
}
# 切换测试环境
if ENVIRONMENT == 'dev':
    APP_REQUEST_HOST = "http://10.10.0.10/cloud-app"  # 开发
    DEVICE_REQUEST_HOST = "http://10.10.0.10/cloud-device"
    ENVIRONMENT_PROPERTIES_PATH = BASE_ENVIRONMENT_PATH + 'dev.properties'
    SIGN_KEY = SIGNS['dev']['key']
    SIGN_SECRET = SIGNS['dev']['secret']
if ENVIRONMENT == 'release_ip':
    ENVIRONMENT = 'release'
    APP_REQUEST_HOST = "http://8.136.251.47/cloud-app"  # 预发 - ip
    DEVICE_REQUEST_HOST = "http://8.136.251.47/cloud-device"
    ENVIRONMENT_PROPERTIES_PATH = BASE_ENVIRONMENT_PATH + 'release.properties'
    SIGN_KEY = SIGNS['pro']['key']
    SIGN_SECRET = SIGNS['pro']['secret']
if ENVIRONMENT == 'release':
    APP_REQUEST_HOST = "https://pre-apis-cn-hangzhou.qamsong.com/cloud-app"  # 预发 - 域名
    DEVICE_REQUEST_HOST = "https://pre-apis-cn-hangzhou.qamsong.com/cloud-device"
    ENVIRONMENT_PROPERTIES_PATH = BASE_ENVIRONMENT_PATH + 'release.properties'
    SIGN_KEY = SIGNS['pro']['key']
    SIGN_SECRET = SIGNS['pro']['secret']
if ENVIRONMENT == 'prod':
    APP_REQUEST_HOST = "https://apis-cn-hangzhou.qamsong.com/cloud-app"  # 生产
    DEVICE_REQUEST_HOST = "https://apis-cn-hangzhou.qamsong.com/cloud-device"
    ENVIRONMENT_PROPERTIES_PATH = BASE_ENVIRONMENT_PATH + 'product.properties'
    SIGN_KEY = SIGNS['pro']['key']
    SIGN_SECRET = SIGNS['pro']['secret']
if ENVIRONMENT == 'local':
    APP_REQUEST_HOST = "http://127.0.0.1:1000"  # 本地
    DEVICE_REQUEST_HOST = "http://127.0.0.1:1006"
    ENVIRONMENT_PROPERTIES_PATH = BASE_ENVIRONMENT_PATH + 'local.properties'
    SIGN_KEY = SIGNS['pro']['key']
    SIGN_SECRET = SIGNS['pro']['secret']
